from app.database import convert
from app.models.po.base_po import BasePO


def save_or_update(table,instance, *criterion):
    record = convert.query(table, *criterion).first()
    count = 0
    if record is not None:
        count = convert.update_model(record, instance.__dict__)
    else:
        count = convert.add_one(instance)

    return count
